/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * <p>Project: jse2302 - ListSort
 * <p>Powered by webrx On 2023-06-25 11:16:08
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ListSort {
    public static void main(String[] args) {
        //根据学生对象
        List<Student> lts = new ArrayList<>(List.of(
                new Student(10, "李四", 80),
                new Student(20, "张三丰", 20),
                new Student(30, "周勇", 50),
                new Student(40, "王强", 90),
                new Student(66, "李强", 95)
        ));
        System.out.println(lts);

        //根据id降序
        Collections.sort(lts,(a,b)->b.getId()-a.getId());
        System.out.println(lts);

        //根据姓名排升序
        Collections.sort(lts,(a,b)->a.getName().compareTo(b.getName()));
        System.out.println(lts);

        for(Student st : lts){
            System.out.println(st);
        }

        
        System.exit(0);

        //字符串排序
        List<String> lists = new ArrayList<>(List.of("c", "java", "python", "html", "javascript"));
        System.out.println(lists);
        Collections.sort(lists);
        System.out.println(lists);
        Collections.sort(lists, (a, b) -> b.compareTo(a));
        System.out.println(lists);
        Collections.shuffle(lists);
        System.out.println(lists);
        //根据字符串个数
        Collections.sort(lists, (a, b) -> a.length() - b.length());
        System.out.println(lists);
        Collections.sort(lists, (a, b) -> b.length() - a.length());
        System.out.println(lists);


        //数字
        List<Integer> nums = new ArrayList<>(List.of(1, 2, 3, 9, 6, 0, 10));
        System.out.println(nums);
        //升序 Collections 集合的工具类
        Collections.sort(nums);
        System.out.println(nums);

        //降序 Collections 集合的工具类
        Collections.sort(nums, (a, b) -> b - a);
        System.out.println(nums);

        //乱序Collections 集合的工具类
        Collections.shuffle(nums);
        Collections.shuffle(nums);
        Collections.shuffle(nums);
        Collections.shuffle(nums, new Random(3));
        //Collections.sort(nums, (a, b) -> Math.random() > .5 ? 1 : -1);
        System.out.println(nums);


    }

    public static void mm(String[] args) {
        List<Integer> li1 = new ArrayList<>();
        System.out.println(li1);

        //li2 只读的
        List<Integer> li2 = List.of(10, 20, 30, 40);
        System.out.println(li2);


        List<Integer> li3 = new ArrayList<>(li2);
        li3.add(50);
        System.out.println(li3);

        //遍历数组或集合的元素
        for (int i : li3) {
            System.out.println(i);
        }

        List<List<Integer>> ls = new ArrayList<>();
        ls.add(List.of(10, 20));
        ls.add(List.of(11, 22, 33));
        ls.add(List.of(110, 2200, 33000));
        System.out.println(ls);
        System.out.println(ls.size());

        for (List<Integer> list : ls) {
            for (Integer i : list) {
                System.out.print(i + " ");
            }
            System.out.println();
        }
        List<int[]> ln = new ArrayList<>();


    }
}
